# 2 列表
bicycles = ['trek', 'cannondale', 'redline', 'specialized']

## 2.1 访问列表里的倒数第一个\倒数第四个元素
# print(bicycles[-1].title())
# print(bicycles[-4].title())

## 2.2 在列表末尾添加元素 append、在列表中插⼊元素 insert
## 使⽤ del 语句删除元素\使⽤ pop() ⽅法删除元素、根据值删除元素 remove
# bicycles.append('blackline')
# bicycles.insert(1, 'blackline')
# del bicycles[0]
# print(bicycles)
# popped_motorcycle = bicycles.pop()
# print(bicycles)
# print(popped_motorcycle)
# bicycles.append(popped_motorcycle)
# print(bicycles)
# popped_motorcycle = bicycles.pop(1)
# print(bicycles)
# print(popped_motorcycle)
# bicycles.remove('redline')
# print(bicycles)

## 2.3 对列表按字母顺序排序 sort
# bicycles.sort()         # 永久按首字母改变顺序
# print(bicycles)
# bicycles.sort(reverse=True)
# print(sorted(bicycles)) # 临时按首字母改变顺序
# print(sorted(bicycles, reverse=True))
# bicycles.reverse()      # 永久反向顺序
# print(bicycles)

## 2.4 列表生成及列表表达式，列表切片、复制
'''
字典推导式：{k:v for ...}
集合推导式：{x for ...}
生成器表达式：(x for ...)（惰性计算，节省内存）
'''
# numbers = list(range(1, 6, 2)) #[1,6),步长2
# print(numbers)

# squares = [value**2 for value in range(1, 11)]
# squares = [ x for x in range(10) if x % 2 == 0]
# squares = [x if x % 2 == 0 else 0 for x in range(1, 11)]
# squares = [(x, y) for x in range(3) for y in range(2)]
# matrix = [[1,2,3], [4,5,6], [7,8,9]]
# squares = [num for row in matrix for num in row]
# print(squares)
# gen = (x**2 for x in range(5))
# print(list(gen))

## 2.5 元组（不可变的列表）
# dimensions = (200, 50)
# print(dimensions)

# dimensions = (400, 100)
# for dimension in dimensions:
#     print(dimension)